﻿$(function() {
/**
 * 日分析
 */
    var dayline = echarts.init(document.getElementById('dayline'));
    optionline = {
        tooltip : {
            trigger: 'axis',
            axisPointer: {
		        type: 'shadow'
		    }
        },
        backgroundColor:'#e0e0e0',
        grid: {
            top: '15%',
            left: '4%',
            right: '5%',
            bottom:'20%',
            containLabel: true
        },
        legend: {
        	bottom: '25',
	        data:['平均开动率','平均满载率']
	    },
        xAxis:  {
            type: 'category',
            boundaryGap: [1, 1],
            data: [],//['1','2','3','4','5','6'],
            splitLine:{
            	show:false
            }
        },
        yAxis: {
            type: 'value',
            name:'开动率(%)',
            axisLabel:{
	    		 formatter: '{value}'
	    	 },
            splitLine:{
            	show:false
            }
        },
        dataZoom:{
	    	type:'slider',
	    	start:0,
	    	end:100,
//	    	labelFormatter: function (value) {
//	    	    return value; // 返回最终的label内容。
//	    	},
	    	bottom:1
	    },
        series: [{
             name:'平均开动率',
             type:'line',
             data:[]//[0.8,0.9,0.84,0.7,0.8,0.91],
         },{
             name:'平均满载率',
             type:'line',
             data:[]//[0.83,0.75,0.89,0.91,0.79,0.93],
         }]
    };
    dayline.setOption(optionline);
    
    
    /**
     * 周分析
     */
        var weekline = echarts.init(document.getElementById('weekline'));
        optionweek = {
            tooltip : {
                trigger: 'axis',
                axisPointer: {
    		        type: 'shadow'
    		    }
            },
            backgroundColor:'#e0e0e0',
            grid: {
                top: '15%',
                left: '4%',
                right: '5%',
                bottom:'20%',
                containLabel: true
            },
            legend: {
            	bottom: '25',
    	        data:['平均开动率','平均满载率']
    	    },
            xAxis:  {
                type: 'category',
                boundaryGap: [1, 1],
                data: [],//['1','2','3','4','5','6'],
//                axisLabel:{
//    	    		formatter: '{value}周'
//    	    	 },
                splitLine:{
                	show:false
                }
            },
            yAxis: {
                type: 'value',
                name:'开动率(%)',
                axisLabel:{
    	    		 formatter: '{value}'
    	    	 },
                splitLine:{
                	show:false
                }
            },
            dataZoom:{
    	    	type:'slider',
    	    	start:0,
    	    	end:100,
//    	    	labelFormatter: function (value) {
//    	    	    return value; // 返回最终的label内容。
//    	    	},
    	    	bottom:1
    	    },
            series: [{
                 name:'平均开动率',
                 type:'line',
                 data:[]//[0.8,0.9,0.84,0.7,0.8,0.91],
             },{
                 name:'平均满载率',
                 type:'line',
                 data:[]//[0.83,0.75,0.89,0.91,0.79,0.93],
             }]
        };
        weekline.setOption(optionweek);
        
        /**
         * 月分析
         */
            var monthline = echarts.init(document.getElementById('monthline'));
            optionmonth = {
                tooltip : {
                    trigger: 'axis',
                    axisPointer: {
        		        type: 'shadow'
        		    }
                },
                backgroundColor:'#e0e0e0',
                grid: {
                    top: '15%',
                    left: '4%',
                    right: '5%',
                    bottom:'20%',
                    containLabel: true
                },
                legend: {
                	bottom: '25',
        	        data:['平均开动率','平均满载率']
        	    },
                xAxis:  {
                    type: 'category',
                    boundaryGap: [1, 1],
                    data:[],// ['1','2','3','4','5','6'],
//                    axisLabel:{
//        	    		formatter: '{value}月'
//        	    	 },
                    splitLine:{
                    	show:false
                    }
                },
                yAxis: {
                    type: 'value',
                    name:'开动率(%)',
                    axisLabel:{
        	    		 formatter: '{value}'
        	    	 },
                    splitLine:{
                    	show:false
                    }
                },
                dataZoom:{
        	    	type:'slider',
        	    	start:0,
        	    	end:100,
//        	    	labelFormatter: function (value) {
//        	    	    return value; // 返回最终的label内容。
//        	    	},
        	    	bottom:1
        	    },
                series: [{
                     name:'平均开动率',
                     type:'line',
                     data:[],//[0.8,0.9,0.84,0.7,0.8,0.91],
                 },{
                     name:'平均满载率',
                     type:'line',
                     data:[],//[0.83,0.75,0.89,0.91,0.79,0.93],
                 }]
            };
            monthline.setOption(optionmonth);

    /**
     * 初始化
     * */
    var vm = new Vue({
	    el: '#itemData',
	    data:{item:[]}
	}); 
    var lineId=0;var equId=0;
    $('#ss').slider('setValue',parseInt(moment().format("x")));
    var getsliderTime=$('#ss').slider('getValue');
	var	time=moment(getsliderTime).format("YYYY-MM-DD");
	getData();
    function getData(){
    	$.post(basePath+"/line/lossElectricityData.json",{"lineId":lineId,"equId":equId,belongDate:time},function(res){
    		vm.$set('item',res);
//    		if(res.success){
    			dayline.setOption({
			        xAxis: {
			            data: res.everyday
			        },
			        series: [{
			        	name:'平均开动率',
			            data: res.dayStartRate
			        },{
			        	name:'平均满载率',
			        	data:res.dayFullRate
			        }]
    			});
    			weekline.setOption({
			        xAxis: {
			            data: res.everyweek
			        },
			        series: [{
			        	name:'平均开动率',
			            data: res.weekStartRate
			        },{
			        	name:'平均满载率',
			        	data:res.weekFullRate
			        }]
    			});
    			monthline.setOption({
			        xAxis: {
			            data: res.everymonth
			        },
			        series: [{
			        	name:'平均开动率',
			            data: res.monthStartRate
			        },{
			        	name:'平均满载率',
			        	data:res.monthFullRate
			        }]
    			});
//    		}else{
//    			alert("日期无效");
//    		}	
    	});
    }
    
    /**
     * slider滑动事件
     * */
    $('#ss').slider({
       onComplete:function(value){//滑块值改变时触发
       	time=moment(value).format('YYYY-MM-DD');
       	getData();
       }
    });
    
    /**
     * 自定义时间按钮的点击事件
     * */
	 $("#defineTime").click(function (){
		 var mePanel = $('#defineTimeWin');
	   	 mePanel.dialog('open');
	 });
	 
	 /**
	  * 切换设备的点击事件
	  * */
	var mePanel = $('#switchEquip');
	$("#linetree").tree({
		onClick: function(node) {
			if (node.url) {
				lineId=node.id;
				var lineGrid = $('#lines_data');
				lineGrid.datagrid('load',{
					lineId:node.id
				});
				lineGrid.datagrid('getPanel').panel('setTitle',node.text);
			}
		}
	});
	$('#lines_data').datagrid({
  		//双击设备时，根据选中设备刷新
  		onDblClickRow: function(rowIndex, rowData){
  			equId=rowData.id;
  			time=moment($('#ss').slider('getValue')).format("YYYY-MM-DD");
            getData();
  		    mePanel.dialog('close');
  		}
	});
    $("#switchEquipOK").click(function(){
    	var row = $('#lines_data').datagrid('getSelected');
    	if(row){
    		equId=row.id;
  			time=moment($('#ss').slider('getValue')).format("YYYY-MM-DD");
    		getData();
  			$('#switchEquip').dialog('close');
    	}else{
    		$.messager.alert({showSpeed:100,title:'消息提示',msg:'请选择一条设备记录!',timeout:3000});
    	}
    });
});